package openGl.utils;

import android.content.Context;
import android.opengl.GLES20;

import camera.OpenGl.ShaderProgram;
import customview.ike.com.customviewproject.R;

/**
 * Created by Administrator on 2017/12/28.
 */

public class TexureShaderProgram extends ShaderProgram {

    public final int aTextureCoordinates;
    public final int uTexture;
    public final int aPosition;
    public final int uMatrix;

    public TexureShaderProgram(Context context) {
        super(context, R.raw.texture_vertex_shader, R.raw.texture_fragment_shader);
        aTextureCoordinates = GLES20.glGetAttribLocation(program, A_TEXTURE_COORDINATES);
        aPosition = GLES20.glGetAttribLocation(program, A_POSITION);
        uMatrix = GLES20.glGetUniformLocation(program, U_MATRIX);
        uTexture = GLES20.glGetUniformLocation(program, U_TEXTURE_UNIT);
        
    }
    public void setUniforms(float[] matrix,int textureId){
        GLES20.glUniformMatrix4fv(uMatrix,1,false,matrix,0);
        GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D,textureId);
        GLES20.glUniform1i(uTexture,0);
    }
}
